<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Ajax中的json</title>
</head>
<body>
    <button id="btn">请求</button>
    <script src="js/createXMLHttpRequest对象.js"></script>
    <script>
        // console.log(xhr)
        var btn = document.getElementById('btn');
        btn.addEventListener('click',function(){
            var xhr = createXMLHttpRequest();
            if (xhr.status === 200 && xhr.readyState === 4){
                // 接收数据
                var data = xhr.responseText
                var json = JSON.parse(data)
                console.log(json)
            }
            var xhr = createXMLHttpRequest();
            xhr.open('post',"server.json")
            xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
            var object = {
                name:'PGone',age:26
            }
            var jsonString = JSON.stringify(object)
            xhr.send(jsonString)
            
        }
        )
    </script>
</body>
</html>